package com.typy.www.tpay.ui.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.typy.www.tpay.LoginActivity;
import com.typy.www.tpay.MainActivity;
import com.typy.www.tpay.bean.bean.HomeBtnBean;
import com.typy.www.tpay.ui.itemview.MineHomeItemView;
import com.typy.www.tpay.ui.itemview.PictureItemView;
import com.typy.www.tpay.util.ClassHoldUtil;
import com.typy.www.tpay.util.Logutil;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 13799 on 2018/6/16.
 */

public class MineGridAdapter extends BaseAdapter {

    private List<HomeBtnBean> list=new ArrayList<>();
    private Context mContext;
    private int mType;

    public void setmType(int mType) {
        this.mType = mType;
    }

    public MineGridAdapter(Context context){
        mContext=context;
    }

    public void setList(List<HomeBtnBean> list) {
        this.list = list;
    }

    @Override
    public int getCount() {
        return list==null?0:list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        if(mType == ClassHoldUtil.DAIQUERENSHOUKUAN||mType == ClassHoldUtil.TOUSUCHULIZHONG){
            PictureItemView itemView = null;
            if (view == null) {
                itemView = new PictureItemView(mContext);
                view = itemView.getmView();
                view.setTag(itemView);
            } else {
                itemView = (PictureItemView) view.getTag();
            }
            itemView.bind(list.get(i));
        }else {
            MineHomeItemView itemView = null;
            if (view == null) {
                itemView = new MineHomeItemView(mContext, mType);
                view = itemView.getmView();
                view.setTag(itemView);
            } else {
                itemView = (MineHomeItemView) view.getTag();
            }
            itemView.bind(list.get(i));
        }
        return view;
    }
}
